﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;

using System.Linq;

using ProjectBase.Core;

using $prjsn$.Common.Validation;

namespace $safeprojectname$
{
    public static partial class Ext
    {
        public static readonly DateTime MinDatumCommon = new DateTime(2000, 1, 1);
        public static readonly DateTime MaxDatumCommon = new DateTime(2100, 1, 1);

        public static readonly IEnumerable<Type> ValidatedStructs = new[]
        {
            typeof (int), typeof (uint), typeof (long), typeof (ulong)
            , typeof (byte), typeof (sbyte), typeof (short), typeof (ushort)
            , typeof (float), typeof (double), typeof (decimal)
        };

        public static TRule SetOrder<TRule>(this TRule rule, int order)
            where TRule : RuleBase
        {
            rule.Order = order;
            return rule;
        }

        public static TRule When<TRule>(this TRule rule, ValidateOn validateOn)
            where TRule : RuleBase
        {
            rule.ValidateOn = validateOn;
            return rule;
        }

        public static TRule WhenCreating<TRule>(this TRule rule)
            where TRule : RuleBase
        {
            rule.ValidateOn = ValidateOn.Add;
            return rule;
        }

        public static TRule WhenCreatingOrUpdating<TRule>(this TRule rule)
            where TRule : RuleBase
        {
            rule.ValidateOn = ValidateOn.Add | ValidateOn.Update;
            return rule;
        }

        public static TRule WhenDeleting<TRule>(this TRule rule)
            where TRule : RuleBase
        {
            rule.ValidateOn = ValidateOn.Delete;
            return rule;
        }

        public static TRule WhenUpdating<TRule>(this TRule rule)
            where TRule : RuleBase
        {
            rule.ValidateOn = ValidateOn.Update;
            return rule;
        }

        public static TRule WhenFiltering<TRule>(this TRule rule)
            where TRule : RuleBase
        {
            rule.ValidateOn = ValidateOn.Find;
            return rule;
        }

        public static TRule AndCanDelete<TRule>(this TRule rule)
            where TRule : RuleBase
        {
            rule.ValidateOn |= ValidateOn.CanDelete;
            return rule;
        }

        public static TRule AndCanEdit<TRule>(this TRule rule)
            where TRule : RuleBase
        {
            rule.ValidateOn |= ValidateOn.CanEdit;
            return rule;
        }

        public static TRule BreakOnError<TRule>(this TRule rule)
            where TRule : RuleBase
        {
            rule.BreakOnError = true;
            return rule;
        }

        public static TRule ApplyOnClient<TRule>(this TRule rule)
            where TRule : RuleBase
        {
            rule.ApplyOn = ApplyOn.Client;
            return rule;
        }
        public static TRule ApplyOnServer<TRule>(this TRule rule)
            where TRule : RuleBase
        {
            rule.ApplyOn = ApplyOn.Server;
            return rule;
        }
        public static TRule ApplyEverywhere<TRule>(this TRule rule)
            where TRule : RuleBase
        {
            rule.ApplyOn = ApplyOn.Server | ApplyOn.Client;
            return rule;
        }
    }
}